package com.aquarium.ui.controller;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aquarium.R;
import com.aquarium.module.ModuleController;

public class ModuleUnswitchableLayout extends LinearLayout {

	protected Activity mActivity;
	protected Handler mHandler;
	
	protected String mModuleName;

	protected View mView;
	protected ModuleController mModuleController;

	protected TextView mModuleTextView;
	protected Button mUVLSettingButton;

	public ModuleUnswitchableLayout(Activity activity, Handler handler, String moduleName,Class settingClass) {
		super(activity);
		mActivity = activity;
		mHandler = handler;
		mModuleName = moduleName;
		
		mModuleController = ModuleController.getInstance(activity);

		LayoutParams params = new LinearLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

		LinearLayout layout = new LinearLayout(activity);
		layout.setLayoutParams(params);
		initLayout(settingClass);
	}

	public void initLayout(Class settingClass) {
		findViews();
		setSettingButtonListener(settingClass);
		mModuleTextView.setText(mModuleName);
	}
	
	protected void findViews() {
		mView = View.inflate(mActivity, R.layout.module_ctrl_type_2, this);
		mModuleTextView = (TextView) mView.findViewById(R.id.module_name);
		mUVLSettingButton = (Button) mView.findViewById(R.id.time_setting_btn);
	}

	protected void setSettingButtonListener(final Class cls) {
		mUVLSettingButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View view) {
				Intent intent = new Intent();
				intent.setClass(mActivity, cls);
				mActivity.startActivity(intent);
			}
		});
	}
}

